package board;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferStrategy;

public class PanelGroup extends Canvas implements ActionListener{
	
	   MyJPanel mjp;
	   Image dice[]; 

	   JPanel info;
	   JLabel totalLabel;
	   JFrame mjf = new JFrame("Dice Panel");
	 
	   JPanel control;
	   JButton cont;

	   int result=0;
	   int die1, die2;

	   boolean first = true;
	   boolean begin = true;

	   public PanelGroup()
	   {
	      info = new JPanel();
	      totalLabel = new JLabel("Total: ");
	      info.add(totalLabel);
	      mjf.getContentPane().add(info, "South");
	      
	      control = new JPanel();
	      cont = new JButton("Roll Dice");
	      cont.addActionListener(this);
	      control.add(cont);
	      mjf.getContentPane().add(control,"North");

	      dice = new Image[6];
	      dice[0] = new ImageIcon("1.jpg").getImage();
	      dice[1] = new ImageIcon("2.jpg").getImage();
	      dice[2] = new ImageIcon("3.jpg").getImage();
	      dice[3] = new ImageIcon("4.jpg").getImage();
	      dice[4] = new ImageIcon("5.jpg").getImage();
	      dice[5] = new ImageIcon("6.jpg").getImage();
	      
	      mjp = new MyJPanel();
	      mjp.setImages(dice);
	      mjp.setBackground(Color.white);
	      mjf.getContentPane().add(mjp, "Center");

	      mjf.setSize(400,400);
	      mjf.setVisible(true);
	   }

	   public void actionPerformed(ActionEvent e)
	   {
	      // Roll dice 
	      begin = false;
	      die1 = (int)(Math.random() * 6 + 1);
	      die2 = (int)(Math.random() * 6 + 1);
	         
	      result = die1 + die2; 
	      totalLabel.setText(" Total: " + result);
	     
	      mjp.setAll(die1, die2, result, begin);
	      mjp.repaint();
	   }

}
